package com.student_system.system.controller;

import com.student_system.system.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljy
 * @since 2025-05-14
 */
@RestController
@RequestMapping("/sysUserRole")
public class SysUserRoleController {
    @Autowired
    ISysUserRoleService sysUserRoleService;

    @GetMapping("/{userId}")
    public List<Integer> getUserRoleIds(@PathVariable Integer userId) {
        return sysUserRoleService.getRoleIdByUserId(userId);
    }

    @PostMapping("/save/{userId}/{roleids}")//注意
    public String saveUserRole(@PathVariable("userId") Integer userId, @PathVariable("roleids") Integer roleIds){

        sysUserRoleService.saveUserRoles(userId,Arrays.asList(roleIds));
        return "success";
    }
}
